import Vue from 'vue'; // 引入vue
var vm = new Vue(); // 实例化
import store from '@/store'

/**
 * 判断是否登陆
 */
function jugeIsLogin() {
    var isLogin = store.state.vuex_user.hasOwnProperty("token");
    if (!isLogin) {
        vm.$u.toast("暂未登陆");
        const pages = getCurrentPages(); //页面对象
        const currectPage = pages[pages.length - 1].route;
        store.state.prev_page = currectPage


        setTimeout(() => {
            uni.switchTab({
                url: "/pages/center/center",
            });
        }, 500);
    }
    return isLogin
}

/**
 * 订单支付成功查询
 */
function orderStatusCheck(ordersn) {
    return new Promise((resove) => {
        var from = {
            ordersn: ordersn
        }
        vm.$u.api.orderPayStatusApi(from).then(res => {
            vm.$u.vuex("vuex_car_list", [])
            if (res.is_paid === 1) {
                uni.navigateTo({
                    url: '/pages/myfoods/myfoods?router=2'
                });
            } else {
                vm.$u.toat("支付失败")
            }
        })
    })
}

export {
    jugeIsLogin,
    orderStatusCheck
}